package com.JUC.cha06.sec01;

import java.util.concurrent.TimeUnit;

public class VolatileSeeDemo {

    static volatile boolean flag = true;

    public static void main(String[] args) {

        new Thread(() -> {
            System.out.println("---- come in t1");
            while (flag){
            }
            System.out.println("---- t1线程结束：flag = false\t" + flag);
        }, "t1").start();

        // 暂停几秒钟线程
        try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); }

        flag = false;

        System.out.println("---- flag设置为false\t" + flag);


    }
}
